package codeTop;

import java.util.Stack;

public class q232 {
    class MyQueue {
        Stack<Integer> stackIn;
        Stack<Integer> stackOut;

        public MyQueue() {
            stackIn = new Stack<>();
            stackOut = new Stack<>();
        }

        public void push(int x) {
            stackIn.push(x);
        }

        public int pop() {
            if (stackOut.isEmpty()) {
                transform();
            }
            return stackOut.pop();
        }

        public int peek() {
            if (stackOut.isEmpty()) {
                transform();
            }
            return stackOut.peek();
        }

        public boolean empty() {
            return stackIn.empty()&& stackOut.empty();
        }

        public void transform(){
            while (!stackIn.empty()) {
                stackOut.add(stackIn.pop());
            }
        }
    }
}
